package com.blue.validation.spi;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.blue.validation.Entcode;

public class EntcodeValidator implements ConstraintValidator<Entcode, String>
{
	private static Pattern pattern = Pattern.compile("^([0-9a-zA-Z]){8}-[0-9a-zA-Z]+$");

	public EntcodeValidator()
	{
	}

	@Override
	public void initialize(Entcode anno)
	{
	}

	@Override
	public boolean isValid(String text, ConstraintValidatorContext context)
	{
		if (text == null || text.isEmpty())
			return true;

		Matcher matcher = pattern.matcher(text);
		return matcher.matches();
	}
}
